package com.benjaminwan.read.free.model.bean

import java.util.*

data class DetailListBean(
    private val mDetailBeans: MutableList<DetailBean> = mutableListOf(),
    private val mPostIdBeans: HashMap<String, DetailBean> = HashMap(),
    var lastPage: Int = 1,
    var page: Int = 0,
    var title: String = "",
    var fid: Int = 0,
    var tid: String = "",
    var imagesCount: Int = 0
) {
    fun add(detailBean: DetailBean) {
        mDetailBeans.add(detailBean)
        mPostIdBeans[detailBean.postId] = detailBean
        for (contentImg in detailBean.images) {
            contentImg.floor = detailBean.floor
            contentImg.author = detailBean.author
            contentImg.indexInPage = imagesCount++
        }
    }

    val count: Int
        get() = mDetailBeans.size

    val all: List<DetailBean>
        get() = mDetailBeans

    fun getPostInPage(postId: String?): DetailBean? {
        return mPostIdBeans[postId]
    }

    val contentImages: ArrayList<ContentImg>
        get() {
            val result = ArrayList<ContentImg>()
            for (detail in mDetailBeans) {
                result.addAll(detail.images)
            }
            return result
        }
}